<!DOCTYPE html>
<html>
<head>
	<title>水分检测</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <script src="js/mui.js"></script>
	<script src="js/layui/layui.all.js"></script>
	<script type="text/javascript" src="js/common.js" ></script>
    <link href="css/mui.css" rel="stylesheet"/>
	<link href="css/common.css" rel="stylesheet"/>
	<link href="css/gnxz.css" rel="stylesheet"/>
    <link href="css/xmjc.css" rel="stylesheet"/>
    <!-- Nicky -->
 	<link rel="stylesheet" href="css/nicky.css" /> 
 	<script type="text/javascript" src="js/jquery.min.js" ></script>
 	<script src="js/webdb.js"></script>
	<script type="text/javascript" src="js/function.js" ></script>
	 
</head>
<body>
		<header class="mui-bar mui-bar-nav mui-bar-transparent bg main-header">
		<div class="back"><a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left back" >返回</a></div>
		<!--<div class="back" style="text-align: center;"><a class="mui-icon  mui-pull-center back" >水分检测</a></div>-->
	
	   </header>
	   <div class="bg main-nav" > </div>
	   	
	   <div class="mui-content"   >
	   	
	   		<div class="pBox">
				<div class="pHeader" >水分检测</div>
				<div class="uinfo" >
					<ul>
					  <li><i>磅单号:</i><b class="txtBdid"></b></li>
					  <li><i>车牌号:</i><b class="txtCarnum"></b></li>
				    </ul>
				</div>
		   	</div>

		    <div id="dataList" class="dataList">
				<dl>
					<!--<dd>
						<em>4</em>
						<p>
							<span><b>结果</b><i>12.8</i></span>
							<span class="u"><b>质检员</b><i>12345/张三丰</i></span>
							<span><b>上传人</b><i>11111</i></span>
							<span><b>水分仪</b><i>12345</i></span>
						</p>
					</dd>-->
				</dl>
     			<div class="cc"></div>
	         	<br ><br ><br >
			 </div>
	   </div>
	   <div class="btnBox fixBottom">
		   	<button class="nbtn" id="submit" onclick="upload()" >提交</button> 
		   	<button class="nbtn disable" id="delete">删除</button>  
		   	<button class="nbtn mySwitch disable" id="repeat">复检</button>    
	   </div> 
	  <script>
	  mui.init();
	  var uinfo = null , uid = null , serverData = null , sfyid = null ;
	  mui.plusReady(function(){
	  	uid = getSession('UID');
	  	uinfo = JSON.parse(getSession('UINFO'));
	  	sfyid = getSession('SFYID');
	  	
		serverData = JSON.parse(getSession('serData'));
		
		$('.txtUname').text(serverData.uname);
		$('.txtBdid').text(serverData.bdid);
		$('.txtDesc').text(serverData.desc);
		$('.txtUid').text(serverData.uid);
		$('.txtCarnum').text(serverData.carNum);
	  	
	  	checkUserRose();
	  	
	  	$('.mySwitch').click(function(){
  			if($("#repeat").hasClass('disable')){ return false; }
			if($(this).hasClass('hasset')){
				$(this).removeClass('hasset');
				$('.dataList dl dd>i').remove();
			}else{
			  	$(this).addClass('hasset');
				$('.dataList dl dd').append('<i></i>');
			}
		});
		
		remove('sf');
		$('#dataList dl').empty();
		getSFData();
		setInterval(function(){ 
			addItemToDB(12); 
		},2000);
		
		$('#delete').click(function(){
			if($("#delete").hasClass('disable')){ return false;}
			if($('.dataList dl dd.sel').length<1){
				plus.nativeUI.toast('请选择要删除的数据');
			}else{
				plus.nativeUI.showWaiting("正在删除");
				$('.dataList dl dd.sel').remove();
				setTimeout(function(){ plus.nativeUI.closeWaiting(); },2000);
			}
		});
	});

function getSFData(){
	var where = {ZJNUM:uid};
	select('sf',TBS.sf,{where:where},function(dat){
		if(dat.length){
			var html = '';
			for(i=0;i<dat.length;i++){
				html += getLineHtml(i,dat.item(i));
			}
			$('#dataList dl').html(html);
		}
	});
	initListClick();
}

function getLineHtml(i,dat){
	var html = '<dd><em>'+(i+1)+'</em><p>'
				+'<span><b>结果</b><i>'+dat.ZCLJG+'</i></span>'
				+'<span class="u"><b>质检员</b><i>'+dat.ZWZBY+'</i></span>'
				+'<span><b>上传人</b><i>'+dat.ZJNUM+'</i></span>'
				+'<span><b>水分仪</b><i>'+dat.ZSFID+'</i></span>'
				+'</p></dd>';
	return html;
}

/*
BD_NO:磅单号
ITEM:行项目，回传SAP接口固定值"10"
BITEM:项目号（行项目号用于表格显示数据条数和本地数据操作，不用上传，例：01,02,03....）
ZWZFL:检测项目分类标识（"SF"水份       "ZW"杂物        "ZZ"杂纸）
ZLYFS:来源方式，回传SAP接口固定值"A"
ZJNUM:上传人，用户表中的ID字段
ZWZBY:质检员，数据格式为“质检员编号\质检员姓名”，例："1\张三"
ZSFID:水分仪ID
ZCLJG:结果， 每次水份仪质检数据
ZFJBZ:是否复检，复检为"X"
*/

function addItemToDB(val){
	var dat = {BD_NO:serverData.bdid,ITEM:10,BITEM:0,ZWZFL:'SF',ZLYFS:'A',ZJNUM:uid,ZWZBY:'12/质检员',ZSFID:sfyid,ZCLJG:val,ZFJBZ:''};
	var row = [];
	$.each(dat, function(i,d) {
		row.push(d);
	});
	insert('sf',TBS.sf,row);
	var html = getLineHtml(2,dat);
	$('#dataList dl').append(html); 
	initListClick();
}

function initListClick(){
	$('#dataList dl dd').unbind('tap').on('tap',function(e){
		if($(this).hasClass('sel')){
			$(this).removeClass('sel');
		}else{
			$('.dataList dl dd.sel').removeClass('sel');
			$(this).addClass('sel');
		}
	});
}
function checkUserRose(){ 
	//G 用户管理员，     Z 质检员 无删除复检权限，      B 班长 有删除无复检权限，     F 复检员
	if('G'==uinfo.USERS1){
		
	}else if('B'==uinfo.USERS1){
		$("#delete,#repeat").removeClass('disable');
	}else if('F'==uinfo.USERS1){
		$("#repeat").removeClass('disable');
	}
}
  </script>
</body>
</html>